function findalltest() {
    $.get("/testPaper/findAllTest", {subject: $("#subject").val(), grade: $("#grade").val()}, function (data) {
        xianshi(data);
    }, "json");
}

function xianshi(data) {
    console.log(data.result);
    data = data.result;
    var html = '';
    for (let i = 0; i < data.length; i++) {
        html += '<table class="table">\n' +
            '        <thead>\n' +
            '        <tr>\n' +
            '            <th>id</th>\n' +
            '            <th>' + data[i].id + '</th>\n' +
            '        </thead>\n' +
            '        <tbody>\n' +
            '        <tr class="active">\n' +
            '            <td>考试名称</td>\n' +
            '            <td>' + data[i].test_name + '</td>\n' +
            '        <tr class="success">\n' +
            '            <td>年级</td>\n' +
            '            <td>' + data[i].grade + '</td>\n' +
            '        <tr class="active">\n' +
            '            <td>科目</td>\n' +
            '            <td>' + data[i].test_subject + '</td>\n' +
            '        <tr class="success">\n' +
            '            <td>总分</td>\n' +
            '            <td>' + data[i].sum_gader + '</td>\n' +
            '        <tr class="active">\n' +
            '            <td>选择题总分</td>\n' +
            '            <td>' + data[i].choose_gader + '</td>\n' +
            /*'        <tr class="active">\n' +
            '            <td>选择题数量</td>\n' +
            '            <td>'+data[i].choose_number+'</td>\n' +
            */'        <tr class="success">\n' +
            '            <td>填空题总分</td>\n' +
            '            <td>' + data[i].completion_gader + '</td>\n' +
            /*'        <tr class="active">\n' +
            '            <td>填空题数量</td>\n' +
            '            <td>'+data[i].completion_number+'</td>\n' +
            */'        <tr class="active">\n' +
            '            <td>判断题总分</td>\n' +
            '            <td>' + data[i].recognized_gader + '</td>\n' +
            /*'        <tr class="active">\n' +
            '            <td>判断题数量</td>\n' +
            '            <td>'+data[i].recognized_gader+'</td>\n' +
            */'        <tr class="success">\n' +
            '            <td>操作</td>\n' +
            '            <td><a href="javascript:delete1(' + data[i].id + ')">删除该题</a>\n' +
            '                &nbsp;&nbsp;&nbsp;&nbsp;\n' +
            '                <a href="javascript:update1(' + data[i].id + ')">修改该试题</a></td>\n' +
            '        </tbody>\n' +
            '    </table>' + '<br><br>';
    }
    $("#findallhtml").html(html);
}

function delete1(id) {
    $.get('/testPaper/delete', {id: id}, function (data) {
        console.log(data.result);
        alert(data.result);
        findalltest();
    }, 'json');
}

function update1(id) {
    localStorage.clear();
    localStorage.setItem("id", id);
    window.location.href = "/html/testpaper/testpaperupdate.html";
}

$(document).ready(function () {
    getSubject("SUBJECT");
    var date = new Date();
    var year = date.getFullYear();
    console.log(year);
    let html = '<option>' + year + '</option>\n' +
        '            <option>' + (year - 1) + '</option>\n' +
        '            <option>' + (year - 2) + '</option>\n' +
        '            <option>' + (year - 3) + '</option>';
    $("#grade").html(html);
});

//获取科目
function getSubject(obj) {
    $.get('/testPaper/getByModel', {select_type: obj}, function (data) {
        console.log(data.result);
        html = '';
        for (let i = 0; i < data.result.length; i++) {
            html += '<option>' + data.result[i].select_name + '<option>';
            console.log(data.result[i].select_name);
        }
        console.log(html);
        $("#subject").html(html);
    }, 'json');
}